﻿@model LeadMaster.ViewModels.ViewModelReferralData

<h2>
@Model.ReferralCat.Description
</h2>

<div class="spacer"></div>
@using (Html.BeginForm("MaintainItems", "ReferralCats", FormMethod.Post, new { @class = "formMaintainItems" }))
{
    @Html.ValidationSummary(true)
    <fieldset style="border-style: none; width: 500px;">
    @Html.HiddenFor(m => m.ReferralData.ReferralDataID)
    <div>
    <label>Parent Category</label>
    </div>
    <div>
    @Html.DropDownList("ReferralCatsID", (SelectList) ViewBag.ReferralCatsID,"Select a category"
        ,new 
        {
         @class="chosen",
         data_placeholder = "Select Parent Category",
         style = "width: 300px;"
        }
        )
    </div>
    <div class="spacer"></div>
    <div>
    <label>Parent Data</label>
    </div>
    <div>
    @Html.DropDownList("ParentReferralDataID", (SelectList)ViewBag.ParentReferralDataID, "Please select a Parent Data Item (if applicable)"
        ,new
            {
                @class="chosen",
                data_placeholder = "Please select Parent Data Item",
                style="width:300px;"
            }
            )
  
    </div>
    <div class="spacer"></div>
    <div>
    <label>Description</label>
    </div>
    <div>
    <textarea rows="5" cols="200" name="ListReferralData" id="ListReferralData">@Model.ListReferralData</textarea>
    </div>
    <div class="spacer"></div>
    <p>
    <input type="submit" value="Save"
    </p>
    </fieldset>
}

<a href="@Url.Action("Index")">Back To List</a>

<script type="text/javascript">
    $(document).ready(function () {

        $(".chosen").chosen();

        $("#ReferralCatsID").change(function () {
            $.ajax({
                type: "GET",
                url: "@(Url.Action("UpdateParentReferralData","ReferralCats"))/?referralcatsid=" + $("#ParentReferralDataID").val() ,
                success: function(data){
                    var ddl = $('#ParentReferralDataID');
                    ddl.empty();
                    $(data).each(function () {
                        ddl.append(
                            $('<option/>', {
                                value: this.ReferralDataID
                            }).html(this.Description)
                        );
                    });
                }
            });
          });

    });
</script>